package com.project.lk.nurseapp.nurse.doctorapply;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.project.lk.nurseapp.R;
import com.project.lk.nurseapp.common.adapter.BaseRecycleViewAdapter;
import com.project.lk.nurseapp.nurse.doctorapply.model.DoctorItemBean;
import com.project.lk.nurseapp.utils.GlideCircleTransform;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 功能介绍：
 * 项目名：
 * 模块名称：
 * 作者：LK
 * 日期：2018/1/9
 * 修改日期：
 */

public class DoctorListAdapter extends BaseRecycleViewAdapter {

    List<DoctorItemBean> mList = new ArrayList<>();
    Context mContext;

    public DoctorListAdapter(List<DoctorItemBean> list, Context context) {
        this.mList = list;
        this.mContext = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_doctor_list_layout, parent, false);
        ViewHolder viewHolder=new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {

        ViewHolder viewHolder = (ViewHolder) holder;

        viewHolder.itemName.setText(mList.get(position).getNickname());
        viewHolder.itemContext.setText(mList.get(position).getSkilful());
        viewHolder.itemPrice.setText("¥"+mList.get(position).getConsultationFee());
        viewHolder.itemPost.setText(mList.get(position).getJob());
        Glide.with(mContext).load(mList.get(position).getHeadImg()).error(R.mipmap.default_error)
                .placeholder(R.mipmap.default_error)
                .bitmapTransform(new GlideCircleTransform(mContext))
                .into(viewHolder.itemIcon);
        viewHolder.itemConsultation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mContext.startActivity(new Intent(mContext,PayDoctorActivity.class)
                .putExtra("pay",mList.get(position)));
            }
        });

        viewHolder.itemIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mContext.startActivity(new Intent(mContext,DoctorMsgActivity.class)
                .putExtra("pay",mList.get(position)));
            }
        });

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.item_icon)
        ImageView itemIcon;
        @BindView(R.id.item_name)
        TextView itemName;
        @BindView(R.id.item_post)
        TextView itemPost;
        @BindView(R.id.item_context)
        TextView itemContext;
        @BindView(R.id.item_consultation)
        TextView itemConsultation;
        @BindView(R.id.item_price)
        TextView itemPrice;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
